package com.bxd.baodan.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bxd.baodan.App;
import com.bxd.baodan.R;
import com.bxd.baodan.activity.MainActivity;
import com.bxd.baodan.activity.MsgActivity;
import com.bxd.baodan.adapter.ViewHolder;
import com.bxd.baodan.app.JsonApi;
import com.bxd.baodan.base.BaseListFragment;
import com.bxd.baodan.item.PlanerBean;
import com.bxd.baodan.util.GlideUtil;
import com.bxd.baodan.util.NetUtil;
import com.bxd.baodan.widget.StarBarView;
import com.google.gson.reflect.TypeToken;
import com.tencent.TIMConversationType;
import com.tencent.qcloud.timchat.ui.ChatActivity;
import com.umeng.analytics.MobclickAgent;

import java.lang.reflect.Type;
import java.util.List;


public class MainGWFragment extends BaseListFragment<PlanerBean.PlanerBean_>  {
    public ImageView ring_msg;
    private View top_bar;

    @Override
    protected void preDone(View v) {

        top_bar =view.findViewById(R.id.title_bar);
        top_bar.setPadding(top_bar.getPaddingLeft(), top_bar.getPaddingTop() + getStatusBarHeight(),
                top_bar.getPaddingRight(), top_bar.getPaddingBottom());


        listView.addHeaderView(View.inflate(getActivity(), R.layout.planer_header, null));
        ring_msg = view.findViewById(R.id.ring_msg);
        ring_msg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (loginStatus()) {
                    Bundle bundle =new Bundle();
                    bundle.putInt("from",1);
                    openActivity(MsgActivity.class,bundle
                    );
                }
            }
        });

        if (((MainActivity) getActivity()).hasUnRead) {
            ring_msg.setImageResource(R.drawable.ring_msg_red);

        } else {
            ring_msg.setImageResource(R.drawable.ring_msg);
        }
        autoRefresh();
    }

    @Override
    protected int getFragmentLayout() {
        return R.layout.fragment_guwen;
    }

    @Override
    protected Type getTypeToken() {
        return new TypeToken<List<PlanerBean.PlanerBean_>>() {
        }.getType();
    }

    @Override
    protected void setUsualNetUtil() {
        netUtil = new NetUtil(getActivity(), JsonApi.PLANNER_LISTS);
    }

    @Override
    protected int getItemLayout() {
        return R.layout.planer_item;
    }

    @Override
    protected void convert(ViewHolder holder, final PlanerBean.PlanerBean_ item) {

        GlideUtil.loadCircle(getActivity(), item.avatar, ((ImageView) holder.getView(R.id.avatar)));
        ((TextView) holder.getView(R.id.nickname)).setText(item.nickname);
        ((TextView) holder.getView(R.id.serviceCount)).setText(item.serviceCount + "");
        ((TextView) holder.getView(R.id.sign)).setText(item.sign);
        ((StarBarView) holder.getView(R.id.star_bar)).setStarRating(item.star);
        holder.getView(R.id.chat).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (loginStatus()) {
                    MobclickAgent.onEvent(App.getContext(), "v6_1_3_SY_zxzx_zx");
                    ChatActivity.navToChat(getActivity(), item.id + "", true,item, TIMConversationType.C2C);
                }
            }
        });

        holder.getView(R.id.main).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (loginStatus()) {
                    MobclickAgent.onEvent(App.getContext(), "v6_1_3_SY_zxzx_zx");
                    ChatActivity.navToChat(getActivity(), item.id + "", true,item,TIMConversationType.C2C);
                }
            }
        });

    }
    @Override
    protected String getArrayStr(String json_data) {
        return "list";
    }
}
